function [mix] = Train_kde(train, params)
%TRAIN_KDE	Train a one-class kernel density estimate classifier, or parzen estimator, using netlab tollbox
%	[mix] = Train_kde(train, params) 
%	
%	Inputs: 
%           train    A 2D (not 3D!) feature matrix. It's training data of one channel
%           params   A structure (optional) with all parameters (in this case, parameters are defined here)
%
%	Outputs:
%           mix   A structure with the trained model
%		
%	
%	See also Train_gmm, processKDE

%	References:
%           Netlab book
%	

%	Copyright 2012 M. A. F. Pimentel
%	This program is free software: you can redistribute it and/or modify
%	it under the terms of the GNU General Public License as published by
%	the Free Software Foundation, either version 3 of the License, or
%	(at your option) any later version.
%	
%	This program is distributed in the hope that it will be useful,
%	but WITHOUT ANY WARRANTY; without even the implied warranty of
%	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%	GNU General Public License for more details.
%	
%	You should have received a copy of the GNU General Public License
%	along with this program.  If not, see <http://www.gnu.org/licenses/>.

%   SVN revision information
%	@author $Author: M. A. F. Pimentel$
%	@version $Revision: 1.0.0.0$
%	@date $Date: 12-Feb-2012 21:27:58$
%	Contact: marco.pimentel@eng.ox.ac.uk
%	Originally written on: GLNXA64

[ntrain, nftrs] = size(train);
dimx = nftrs;

params.nctrs = ntrain; 
params.covartype = 'spherical';
params.plotHist = false; % 1: plot histogram; 0: don't plot.

if ~isfield(params, 'nctrs'), params.nctrs = 2; end
if ~isfield(params, 'covartype'), params.covartype = 'spherical'; end
if ~isfield(params, 'plotHist'), params.plotHist = false; end

%% Train the GMM
mix = gmm(dimx, params.nctrs, 'spherical');
mix.centres = train;
dist = covarParzenWindow(train);
mix.covars = dist*ones(1,params.nctrs);

mix.NDtype = 'kde';
mix.train = train; % will be used in PlotGMM2Dcont.m.
